package com.teichmann;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.repackaged.com.google.common.base.StringUtil;
import com.teichmann.bo.Car;
import com.teichmann.bo.CarQueue;
import com.teichmann.engine.OnlineExecutor;
import com.teichmann.services.CarServices;

@SuppressWarnings("serial")
public class LoadServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

		execute(req, resp);
	}


	private void execute(HttpServletRequest request, HttpServletResponse response)
			throws IOException {

		
		List<CarQueue> cq = CarServices.findNotExecuted();
		
		if (cq.size() == 0 ){
			CarServices.resetQueue();
		}
		else{
			try {
				request.getSession().setAttribute("queue", cq);
				request.setAttribute("firstTime", "true");
				request.getRequestDispatcher("/loadQueue").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
	}

}
